---
title: Retrieve affiliated policies (legacy)
summary: Loads the legacy affiliate-policy list for a policy, filtered by agent/agency number and classified by affiliate type.
status: draft
owner: SAIF Corporation
last_reviewed: 2026-09-01
library: SAIF.Business.View.Policy
reference_type: embedded
operation_id: op-09-retrieve-affiliated-policies
trigger: Consumer reads AffiliatedPolicyCollection (obsolete affiliate members)
---

# Retrieve affiliated policies (legacy)

Loads the legacy affiliate-policy list for a policy — the predecessor to the newer `Associations`/`PolicyAssociationList` mechanism (see [Retrieve policy associations](op-04-retrieve-policy-associations.md)) — filtering results by agent/agency number and marking the source policy as "current" in the resulting collection.

| Field | Value |
| --- | --- |
| **Operation ID** | op-09-retrieve-affiliated-policies |
| **Trigger** | Consumer reads obsolete affiliate members (`clsAffiliatedPolicyCollection.GetAffiliatedPolicyCollection`) |
| **Inputs** | Policy number, `clsPolicyData.AffiliateTypes`, optional agent number / agency sequence number |
| **Outputs** | `clsAffiliatedPolicyCollection` |
| **Primary components** | `clsAffiliatedPolicyCollection.GetAffiliatedPolicyCollection`, `BeforeRetrieve`/`AfterRetrieve`, `SetCurrent` |
| **Entry point** | `SAIF.Business.View.Policy/clsAffiliatedPolicyCollection.vb` |

## Steps

1. Caller invokes `GetAffiliatedPolicyCollection(inDataportal, inPolicyNum, inAffiliateType)`, which builds a `Criteria` and forwards to the `Criteria`-accepting overload ([BR-VP-011](../business-rules.md#br-vp-011-policy-always-affiliated-with-itself)).
2. The `Criteria`-accepting overload branches on `inCriteria.AffiliateType`: if it is `NonAffiliated`, the data-access layer's `CreateObject` is called instead of `RetrieveObject`, producing a new, empty collection without querying the database at all ([BR-VP-013](../business-rules.md#br-vp-013-displayaffiliatedpolices-matrix-controls-display)); otherwise `RetrieveObject` proceeds normally.
3. Framework invokes `BeforeRetrieve`: assigns `MyCriteria.RetrieveSQL`, sets `CommandType = StoredProcedure`, and binds `in_policy_num`, `in_affiliate_type` (the affiliate type name, upper-cased, [SQL-014](../sql/SQL-014-getpolicyaffiliatetype.md)), and `in_include_affil_totals` (`"TRUE"`/`"FALSE"` string literal derived from `MyCriteria.IncludeAffiliateTotals`), plus a cursor parameter `recordset` ([SQL-001](../sql/SQL-001-getpolicyaffiliatelist.md), procedure `pk72846_view_policy.getpolicyaffiliatelist`).
4. Framework executes the request against Oracle.
5. Framework invokes `AfterRetrieve`: loops `Reader.Read`, constructs a `New clsAffiliatedPolicy` and calls `AffiliatedPolicy.Load(MyCriteria.DataPortalInfo, Reader)` per row, then applies an agent/agency filter before adding each row to the collection ([BR-VP-012](../business-rules.md#br-vp-012-affiliated-policy-list-filtered-by-agentagency)):
   - If `MyCriteria.AgentNum = 0 And MyCriteria.AgencySeqNum = 0`, the row is always added (no filter).
   - Else if `MyCriteria.AgentNum <> 0` and matches `AffiliatedPolicy.AgentNum`, the row is added.
   - Else if `MyCriteria.AgencySeqNum <> 0` and matches `AffiliatedPolicy.AgencySeqNum`, the row is added.
   - Rows matching none of these are silently excluded.
6. After the loop, `SetCurrent(MyCriteria.PolicyNum.ToString)` marks the source policy's row as the collection's current item (commented-out code shows an earlier version that instead defaulted to item `0` when the source policy was not found in the result set).
7. `clsPolicyData.SetCurrentAffiliatedPolicy(inPolicyNum)` (in `clsPolicyData.vb`, `#Region "Policy Affiliate"`) provides an alternate entry point that operates on an already-retrieved collection rather than re-querying.*

## Process flow

```mermaid
flowchart TD
	Start(["Consumer requests<br>affiliated policies"]) --> A{AffiliateType =<br>NonAffiliated?}
	A -->|Yes| B["CreateObject: empty<br>collection, no query"]
	A -->|No| C["RetrieveObject:<br>BeforeRetrieve assigns<br>getpolicyaffiliatelist"]
	C --> D["Framework executes<br>against Oracle"]
	D --> E["AfterRetrieve reads rows"]
	E --> F{More rows?}
	F -->|Yes| G["New clsAffiliatedPolicy / Load"]
	G --> H{Agent/agency<br>filter matches?}
	H -->|Yes| I["Add to collection"]
	H -->|No| F
	I --> F
	F -->|No| J["SetCurrent to source<br>policy number"]
	B --> End(["Return clsAffiliatedPolicyCollection"])
	J --> End
```

## Failure and edge-case behavior
- When `AffiliateType = NonAffiliated`, the collection is created empty with no data-access call at all — a caller cannot distinguish "no query needed" from "query returned zero rows" by inspecting the collection alone.*
- The agent/agency filter in `AfterRetrieve` silently drops non-matching rows rather than raising or logging — a caller who expected the full unfiltered affiliate list would see a partial result with no indication rows were excluded.*
- `SetCurrent` assumes the source policy number is present among the retrieved rows; the currently-active code no longer has the fallback-to-item-0 behavior that the commented-out code shows was once in place, so if the source policy is absent the current-item selection is unclear from this pass alone.**

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

## Sources
- `SAIF.Business.View.Policy/clsAffiliatedPolicyCollection.vb`
- `SAIF.Business.View.Policy/clsPolicyData.vb`
